<template>
	<view class="content">
		<view class="row p15 flex" style="background-color:#3476FE ;margin-top: 0;">
			<image class="avatar" :src="helper.host+userinfo.avatar" mode="aspectFill"></image>
			<view class="name f15" style="color: #ffffff;">
				{{ userinfo.nickname }}
			</view>
		</view>
		<view style="width: 94%;margin: 20rpx auto;border-radius: 20rpx;overflow: hidden;">
			<view class="srow flexb p15" @click="checkupdate">
				<view class="flex">
					<image class="icon1" src="../../static/icon/111.jpg" alt="" />
					<view class="name f14">检测新版本</view>
				</view>
				<view class="f13" style="color: #666;">
					{{version}}
				</view>
			</view>
			<view class="srow flexb p15" @click="scanCode">
				<view class="flex">
					<image class="icon1" src="../../static/icon/saoyisao_1.png" alt="" style="width: 38rpx;" />
					<view class="name f14">扫一扫</view>
				</view>
				<view>
					<image class="icon" src="../../static/icon/gengduo.png" mode="aspectFill"></image>
				</view>
			</view>
			<view class="srow flexb p15" @click="navigateTo('/pages/mine/agree')">
				<view class="flex">
					<image class="icon1" src="../../static/icon/222.jpg" alt="" />
					<view class="name f14">关于智能巡边</view>
				</view>
				<view>
					<image class="icon" src="../../static/icon/gengduo.png" mode="aspectFill"></image>
				</view>
			</view>
		</view>
		<view class="srow  p15 tc_btn" @click="loginout">
			<view class="name f14">退出登录</view>
		</view>
		<zy-update theme="blue" :updateurl="updateurl" :noticeflag="true" :h5preview="true" :oldversion="version"
			ref="zyupgrade" @showupdateTips="showupdatetips"></zy-update>
	</view>
</template>
<script>
	import ZyUpdate from '../../components/zy-upgrade/zy-upgrade.vue'
	import helper from '../../common/helper.js';
	import api from '../../common/api.js';
	export default {
		components: {
			ZyUpdate
		},
		data() {
			return {
				userinfo: { 
					group_id: 1,
					nickname: '',
					score: 0,
					dirver: 0
				},
				version: '1.0.2',
				updateurl: 'http://xunjian.kunliwangluo.com/addons/ddrive/user/update',
				isLogin: false,
				helper: []
			};
		},
		onLoad() {
			let that = this
			let token = helper.getUserToken();
			if (token == '') {
				uni.redirectTo({
					url: '/pages/login/login'
				})
			}
			plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {
				that.version = widgetInfo.version
			});
		},
		onShow() {
			console.log(helper)
			this.helper = helper;
			if (!helper.hasLogin()) {
				this.isLogin = false;
			} else {
				this.isLogin = true;
				this.getUserInfo();
			}
		},
		methods: {
			scanCode() {
				uni.scanCode({
					success: function(res) {
						uni.showModal({
							title: '扫码结果',
							content: res.result
						})
						console.log('条码类型：' + res.scanType);
						console.log('条码内容：' + res.result);
					}
				});
			},
			showupdatetips: function(flag) {
				if (flag == 0) {
					uni.showToast({
						title: '已经是最新版本了',
						icon: 'none'
					});
				}
			},
			checkupdate: function() {
				this.$refs.zyupgrade.check_update()
			},
			async getUserInfo() {
				let res = await api.getUserInfo();
				this.userinfo = res.data;
			},
			loginout() {
				uni.clearStorage();
				uni.redirectTo({
					url: '/pages/login/login'
				});
			},
			navigateTo(url) {
				if (!helper.hasLogin()) {
					url = '/pages/login/login'
				}
				console.log(url)
				uni.navigateTo({
					url: url
				});
			}
		}
	};
</script>

<style lang="scss" scoped>
	.row {
		background-color: #ffffff;
		margin-top: 20rpx;
		padding-top: 30rpx;
		padding-bottom: 30rpx;
	}

	.srow {
		background-color: #ffffff;
		padding-top: 30rpx;
		padding-bottom: 30rpx;
		border-bottom: 1px solid #f5f5f5;
	}

	.avatar {
		width: 100rpx;
		height: 100rpx;
		border-radius: 16rpx;
		margin-right: 20rpx;
		border: 6rpx solid #5590F8;
	}

	.icon {
		width: 32rpx;
		height: 32rpx;
	}

	.icon1 {
		width: 34rpx;
		height: 34rpx;
		margin-right: 8rpx;
	}
	.tc_btn{
		text-align: center;
		text-align: center;
		width: 74%;
		margin: 52rpx auto;
		background: #005bea;
		color: #ffffff;
		border-radius: 80rpx;
		padding: 16rpx 0;
	}
</style>